//
//  WaitView.m
//  LoverGo
//
//  Created by liudonghuan on 14-9-10.
//  Copyright (c) 2014年 yexiao. All rights reserved.
//

#import "WaitView.h"

@implementation WaitView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        _waitImg = [[UIImageView alloc]initWithFrame:CGRectMake((SCREEN_WIDTH-140)/2, 20, 140, 140)];
        _waitAI = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
        _waitLab = [[UILabel alloc]initWithFrame:CGRectMake(0, 180, SCREEN_WIDTH, 40)];
        _waitBtn = [[UIButton alloc]initWithFrame:CGRectMake((SCREEN_WIDTH-100)/2, 240, 100, 40)];
        _waitImg.image = [UIImage imageNamed:@"wait.png"];
        [_waitAI setCenter:CGPointMake(SCREEN_WIDTH/2, 130)];
        _waitAI.color = LGCOLOR_blue;
        _waitLab.textAlignment = UITextAlignmentCenter;
        _waitLab.textColor = [UIColor colorWithRed:68/255.0 green:30/255.0 blue:20/255.0 alpha:1];
        [_waitBtn addTarget:self action:@selector(waitBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [_waitBtn setTitle:@"重新加载" forState:UIControlStateNormal];
        [_waitBtn setTitleColor:LGCOLOR_blue forState:UIControlStateNormal];
        _waitBtn.titleLabel.font = [UIFont systemFontOfSize:14.0];

        [self addSubview:_waitImg];
        [self addSubview:_waitAI];
        [self addSubview:_waitBtn];
        [self addSubview:_waitLab];
    }
    return self;
}

-(void)waitBtnClick
{
    [self starttoload];
    
}
-(void)starttoload{
    [_waitDelegate retrytoload:self];
    [_waitAI startAnimating];
    _waitLab.text = @"正在努力加载数据...";
    _waitBtn.hidden = YES;
    _waitImg.hidden = YES;
}
-(void)failtoload{
    [_waitAI stopAnimating];
    _waitLab.text = @"当前网络不可用，请检查你的网络设置";
    _waitBtn.hidden = NO;
    _waitImg.hidden = NO;
    
}

@end
